package com.baide.sanguanheyi.swing;

import com.baide.sanguanheyi.sqlite.Content;

import javax.swing.table.AbstractTableModel;
import java.util.List;

public class TableModel extends AbstractTableModel {

    String[] cName = new String[]{"序号", "总运单号", "运单号", "重量", "海关状态", "件数", "品名"};
    List<Content> data;

    public TableModel(List<Content> data) {
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return cName.length;
    }

    @Override
    public String getColumnName(int column) {
        return cName[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Content bean = data.get(data.size() - rowIndex - 1);
        switch (columnIndex) {
            case 0:
                return data.size() - rowIndex;
            case 1:
                return bean.getLuoDao().get("voyage_no") == null ? "未知" : bean.getLuoDao().get("voyage_no");
            case 2://运单号
                return bean.getBarCode();
            case 3:
                return bean.getWeight() == null ? "暂未获取" : (bean.getWeight() + "g");
            case 4:
                return getOrderString(bean.getCustOrder());
            case 5:
//                return "";
                return bean.getPackNo() == null ? "" : bean.getPackNo();
            case 6:
//                return "";
                return bean.getMainGName();
        }
        return "";
    }

    private String getOrderString(String order) {
        switch (order) {
            case "0":
                return "放行";
            case "1":
                return "查验";
            case "2":
                return "入库";
            case "3":
                return "放行征税";
            case "4":
                return "退运";
            case "5":
                return "拒识";
            case "6":
                return "退单";
        }
        return "未识别";
    }
}
